package com.coocaa.typhoon.api.v1.mysql;

import com.coocaa.cirrus.common.base.model.RespBase;
import com.coocaa.typhoon.api.v1.mysql.model.entity.UserFileEntity;
import com.coocaa.typhoon.api.v1.mysql.service.UserFileQueryService;
import com.coocaa.typhoon.api.v1.mysql.service.UserFileUpdateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author bijiahao
 * @date : 2025/10/21 15:36
 * @description
 */
@RestController
@RequestMapping("/v1/mysql")
@Tag(name = "Mysql测试")
public class TestMysqlController {
    @Autowired
    private UserFileQueryService userFileQueryService;
    @Autowired
    private UserFileUpdateService userFileUpdateService;


    @Operation(summary = "测试保存用户单个")
    @PostMapping(value = "/testSave")
    public RespBase testSave(@RequestBody UserFileEntity entity) {
        userFileUpdateService.save(entity);
        return new RespBase().setSuccessResult();
    }

    @Operation(summary = "测试保存用户批量")
    @PostMapping(value = "/testSaveBatch")
    public RespBase testSaveBatch(@RequestBody List<UserFileEntity> userFileEntityList) {
        userFileUpdateService.save(userFileEntityList);
        return new RespBase().setSuccessResult();
    }

    @Operation(summary = "测试查询用户")
    @PostMapping(value = "/testQuery")
    @Parameters({
            @Parameter(name = "userId", example = "1", description = "用户ID")
    })
    public RespBase<List<UserFileEntity>> testQuery(@RequestParam String userId) throws Exception {
        List<UserFileEntity> res = userFileQueryService.queryByUserId(userId);
        return new RespBase<List<UserFileEntity>>().setData(res).setSuccessResult();
    }

    @Operation(summary = "测试查询数量")
    @PostMapping(value = "/testCount")
    @Parameters({
            @Parameter(name = "userId", example = "1", description = "用户ID")
    })
    public RespBase<Integer> testCount(@RequestParam String userId) throws Exception {
        Integer res = userFileQueryService.testCount(userId);
        return new RespBase<Integer>().setData(res).setSuccessResult();
    }

}
